package ru.isys.view;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class MainPanel extends JPanel
{
 
    JPanel modelPanel;
    GridBagLayout modelPanelLayout;
    GridBagConstraints modelPanelConstraints;
    
    JScrollPane cenralScrollPane;
    JScrollPane westScrollPanel;    
    FileURIAndNsPanel panel;
    public MainPanel() {
        setLayout(null);
        prepareModelPanel();
        prepareWestScrollPanel();       
        validate();
        initHandlers();
    }
    
    public MainPanel(FileURIAndNsPanel panel){        
        setLayout(null);
        prepareFileToOpenPanel(panel);  
        validate();
    }
    
    
    private void prepareModelPanel(){
        modelPanel = new JPanel();
        modelPanel.setSize(350, getHeight() - 15);        
        modelPanelLayout = new GridBagLayout();        
        modelPanelConstraints = new GridBagConstraints();
        modelPanel.setLayout(modelPanelLayout);
        modelPanelConstraints.insets = new Insets(0, 0, 0, 0);
        modelPanelConstraints.gridx = 0;        
    }
    private void prepareWestScrollPanel(){
        westScrollPanel = new JScrollPane(modelPanel);     
        westScrollPanel.setBounds(0, 0, 350, getHeight() - 15);
        add(westScrollPanel);
    }
    
    private void prepareFileToOpenPanel(FileURIAndNsPanel panel){
        this.panel=panel;
        this.panel.setBounds(0, 0,400,200);
        add(this.panel);
    }
    private void initHandlers() {
        addComponentListener(new ComponentListener() {

            @Override
            public void componentResized(ComponentEvent e) {
                if (cenralScrollPane != null) {
                    cenralScrollPane.setBounds(350, 0, getWidth() - 365,
                            getHeight() - 50);
                }

                westScrollPanel.setBounds(0, 0, 350, getHeight() - 50);
                validate();
            }

            @Override
            public void componentMoved(ComponentEvent e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void componentShown(ComponentEvent e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void componentHidden(ComponentEvent e) {
                // TODO Auto-generated method stub

            }

        });
    }
}
